import { Tag } from 'antd';
import React from 'react';
import { lazyLoadIcon } from './iconHook';
export const changeTreeListForColumns = (list) => {
  return list.map((item) => {
    if (item.children) {
      let obj = {
        key: item.id,
        title: item.title,
        parentId: item.parentId,
        icon: lazyLoadIcon(item.icon),
        icons: item.icon,
        sort: item.sort,
        name: item.name ? item.name : '',
        type: item.name ? (
          <Tag color="#87d068">菜单</Tag>
        ) : (
          <Tag color="#2db7f5">目录</Tag>
        ),
        children:
          item.children && item.children.length > 0
            ? changeTreeListForColumns(item.children)
            : '',
      };
      return obj;
    } else {
      let obj = {
        key: item.id,
        title: item.title,
        parentId: item.parentId,
        icon: lazyLoadIcon(item.icon),
        icons: item.icon,
        sort: item.sort,
        name: item.name ? item.name : '',
        type: item.name ? (
          <Tag color="#87d068">菜单</Tag>
        ) : (
          <Tag color="#2db7f5">目录</Tag>
        ),
      };
      return obj;
    }
  });
};

export const changeTreeListForSelect = (list) => {
  return list.map((item) => {
    if (item.children) {
      let obj = {
        value: item.id,
        label: item.title,
        children:
          item.children && item.children.length > 0
            ? changeTreeListForSelect(item.children)
            : '',
      };
      return obj;
    } else {
      let obj = {
        value: item.id,
        label: item.title,
      };
      return obj;
    }
  });
};
